<%@page import="com.module.admin.prj.enums.PrjInfoStatus"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/inc/sys.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${projectName}-${user.nickname}</title>
<jsp:include page="/WEB-INF/view/inc/css.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="/WEB-INF/view/inc/header.jsp"></jsp:include>
	<div class="container">
		<jsp:include page="/WEB-INF/view/admin/comm/left.jsp"></jsp:include>
		<div class="c-right">
			<div class="panel panel-default">
				<div class="panel-heading panel-heading-tool">
					<div class="row">
						<div class="col-sm-5 title">欢迎您 <b><a href="${webroot}/sysUser/f-view/main.shtml">${user.nickname}</a></b></div>
						<div class="col-sm-7 text-right">
							<%-- <div class="btn-group">
						  		<a href="${webroot}/cliInfo/f-view/monitor.shtml" target="_blank" class="btn btn-default btn-sm">Agent监控</a>
							</div>
							<div class="btn-group jutil-btns" data-select="btn-success" data-def="btn-default">
						  		<a href="javascript:info.changeQuery('10');" class="btn btn-sm <c:choose><c:when test="${param.searchType==20}">btn-default</c:when><c:otherwise>btn-success</c:otherwise></c:choose>">我的收藏</a>
						  		<a href="javascript:info.changeQuery('20', 'filter');" class="btn btn-sm <c:choose><c:when test="${param.searchType==20}">btn-success</c:when><c:otherwise>btn-default</c:otherwise></c:choose>">所有</a>
							</div> --%>
						</div>
					</div>
				</div>
				<div class="panel-body">
					<div class="row" id="infoPanel" style="min-height: calc(100% - 100px);padding: 5px 25px 0px 25px;">
						<div class="row">
							<my:auth mid="workbenchAppSum">
							<div class="col-sm-4 col-md-4" style="padding: 0px 10px;">
								<div class="thumbnail" style="margin-bottom: 15px;border-radius: 0px;">
									<div class="caption">
										<p style="font-size: 20px;margin-bottom: 10px;">应用总数：<b id="appSumPanel">--</b></p>
									    <p><span class="text-success">近一月发布：<b id="appSumJyyPanel">--</b></span> / <span class="text-info">今年发布：<b id="appSumJnPanel">--</b></span></p>
									    <p>历史总发布：<b id="appSumLszsPanel">--</b></p>
									</div>
								</div>
							</div>
							</my:auth>
							<my:auth mid="workbenchTtsProject">
							<div class="col-sm-4 col-md-4" style="padding: 0px 10px;">
								<div class="thumbnail" style="margin-bottom: 15px;border-radius: 0px;">
									<div class="caption">
										<p style="font-size: 20px;margin-bottom: 10px;">定时任务总数：<b id="ttsProjectJobPanel">--</b></p>
									    <p><span class="text-success">正常任务：<b id="ttsProjectNormalPanel">--</b></span> / <span class="text-danger">停止任务：<b id="ttsProjectStopPanel">--</b></span></p>
									    <p>项目总数：<b id="ttsProjectSumPanel">--</b>&nbsp;&nbsp;&nbsp;
									    	<a href="${webroot}/ttsTaskProject/f-view/manager" class="text-muted" title="进入定时任务的[项目管理]维护任务"><small>编辑</small></a>
									    </p>
									</div>
								</div>
							</div>
							</my:auth>
							<!-- <div class="col-sm-4 col-md-4" style="padding: 0px 10px;">
								<div class="thumbnail" style="margin-bottom: 15px;border-radius: 0px;">
									<div class="caption">
										<p style="font-size: 20px;">应用总数：<b id="appSumPanel">0</b></p>
									    <p>近一月发布数：<b id="appSumJyyPanel">0</b> / 今年发布数：<b id="appSumJnPanel">0</b></p>
									    <p>历史总发布数：<b id="appSumLszsPanel">0</b></p>
									</div>
								</div>
							</div> -->
						</div>
						<div class="row main">
							<my:auth mid="workbenchAppInfo">
							<div class="col-sm-6 item">
								<div class="panel panel-default">
									<div class="panel-heading title">
										<div class="row">
											<div class="col-sm-8">应用列表-我的</div>
											<div class="col-sm-4 right"><a href="${webroot}/appInfo/f-view/manager" class="text-muted">更多</a></div>
										</div>
									</div>
									<div class="panel-body item-body" id="appInfoPanel" style="padding: 0px;">
									</div>
								</div>
							</div>
							</my:auth>
							
							<my:auth mid="workbenchPrjInfo">
							<div class="col-sm-6 item">
								<div class="panel panel-default">
									<div class="panel-heading title">
										<div class="row">
											<div class="col-sm-8">服务列表-我的收藏</div>
											<div class="col-sm-4 right"><a href="${webroot}/prjInfo/f-view/manager" class="text-muted">更多</a></div>
										</div>
									</div>
									<div class="panel-body item-body" id="prjInfoPanel" style="padding: 0px;">
									</div>
								</div>
							</div>
							</my:auth>
						
						</div>
								  
					</div>
					<!-- <div id="infoPage" class="table-page-panel"></div> -->
				</div>
			</div>
		</div>
	</div>

	<jsp:include page="/WEB-INF/view/inc/js.jsp"></jsp:include>
	<jsp:include page="/WEB-INF/view/inc/utils/page.jsp"></jsp:include>
<script type="text/javascript">
var info = {
		init: function() {
			<my:auth mid="workbenchTtsProject">
			info.loadTtsProject();
			</my:auth>
			<my:auth mid="workbenchAppSum">
			info.loadAppSum();
			</my:auth>
			<my:auth mid="workbenchAppInfo">
			info.loadAppInfo();
			</my:auth>
			<my:auth mid="workbenchPrjInfo">
			info.loadPrjInfo();
			</my:auth>
		},
		loadTtsProject: function() {
			JUtil.ajax({
				url : '${webroot}/view/f-json/cardInfo',
				data : { type: 'ttsProject' },
				success : function(json) {
					if (json.code === 0) {
						var list = json.body.projects;
						if (!list) {
							return;
						}
						var jobSum = 0;
						var projectNum = 0;
						var normalNum = 0;
						var stopNum = 0;
						$.each(list, function(i, item) {
							jobSum += item.total;
							projectNum ++;
							if(item.status === 0) {
								normalNum += item.total;
								//代表continue
								return true;
							} else if(item.status === 50) {
								stopNum += item.total;
								return true;
							}
						});
						$('#ttsProjectJobPanel').empty().append(jobSum);
						$('#ttsProjectSumPanel').empty().append(projectNum);
						$('#ttsProjectNormalPanel').empty().append(normalNum);
						$('#ttsProjectStopPanel').empty().append(stopNum);
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					 else if(json.code == '10002')
						message('暂时没有开通redis的查看值功能');
					else
						message(json.message);
				}
			});
		},
		loadAppSum: function() {
			JUtil.ajax({
				url : '${webroot}/view/f-json/cardInfo',
				data : { type: 'appSum' },
				success : function(json) {
					if (json.code === 0) {
						var obj = json.body.appSum;
						$('#appSumPanel').empty().append(obj.sumApp);
						$('#appSumJyyPanel').empty().append(obj.sumPubJyy);
						$('#appSumJnPanel').empty().append(obj.sumPubJn);
						$('#appSumLszsPanel').empty().append(obj.sumPubAll);
					}
					else if (json.code === -1)
						message(JUtil.msg.ajaxErr);
					 else if(json.code == '10002')
						message('暂时没有开通redis的查看值功能');
					else
						message(json.message);
				}
			});
		},
		loadAppInfo: function() {
			var panel = $('#appInfoPanel');
			if(JUtil.isEmpty(panel.html())) {
				return;
			}
			panel.empty();
			JUtil.ajax({
				url : '${webroot}/appInfo/f-json/pageQuery',
				data : { page: 1, size: 20 },
				beforeSend: function(){ panel.append('<span class="label label-warning">加载信息中...</span>'); },
				error : function(json){ panel.append('<span class="label label-danger">加载信息出错了!</span>'); },
				success : function(json){
					var cont = [];
					if(json.code === 0) {
						if(json.body.rows.length>0) {
							cont.push('<table class="table table-striped table-hover" style="border:0px;"><thead><tr class="info">',
									'<th>名称</th>', 
			                         '<th width="120">操作</th>',
			                         '</tr></thead><tbody>');
							$.each(json.body.rows, function(i, obj) {
								cont.push('<tr>',
								    '<td>',obj.name,'(',obj.code,')</td>',
							    	'<td><a class="text-success" href="${webroot}/appInfo/f-view/edit?tab=ant&aiId=',obj.aiId,'" title="查看原型列表">原型</a>',
							    		'&nbsp;&nbsp;&nbsp;<a class="text-success" href="${webroot}/appInfo/f-view/edit?tab=apiAutoTest&aiId=',obj.aiId,'" title="API的自动化测试">自动化测试</a>',
							    	'</td>',
								'</tr>');
							});
						} else {
							cont.push('<span class="label label-success">暂无记录</span>');
						}
						cont.push('</tbody></table>');
					}
					else alert(JUtil.msg.ajaxErr);
					panel.empty().append(cont.join(''));
				}
			});
		},
		loadPrjInfo: function() {
			var panel = $('#prjInfoPanel');
			if(JUtil.isEmpty(panel.html())) {
				return;
			}
			panel.empty();
			JUtil.ajax({
				url : '${webroot}/prjInfo/f-json/pageQuery',
				data : { page: 1, size: 20, searchType: 10 },
				beforeSend: function(){ panel.append('<span class="label label-warning">加载信息中...</span>'); },
				error : function(json){ panel.append('<span class="label label-danger">加载信息出错了!</span>'); },
				success : function(json){
					var cont = [];
					if(json.code === 0) {
						if(json.body.rows.length>0) {
							cont.push('<table class="table table-striped table-hover" style="border:0px;"><thead><tr class="info">',
									'<th>服务名称</th>', 
			                         '<th width="150">操作</th>',
			                         '</tr></thead><tbody>');
							$.each(json.body.rows, function(i, obj) {
								cont.push('<tr>',
								    '<td>',obj.name,'(',obj.code,')</td>',
							    	'<td><a class="text-success" href="${webroot}/prjInfo/f-view/edit?tab=config&prjId=',obj.prjId,'" title="查看配置文件">配置文件</a>',
							    		'&nbsp;&nbsp;&nbsp;<a class="text-success" href="${webroot}/prjInfo/f-view/edit?tab=config&prjId=',obj.prjId,'" title="查看API列表">API</a>',
							    		'&nbsp;&nbsp;&nbsp;<a class="text-success" href="${webroot}/prjInfo/f-view/edit?tab=version&prjId=',obj.prjId,'" title="部署版本">版本</a>',
							    	'</td>',
								'</tr>');
							});
						} else {
							cont.push('<span class="label label-success">暂无记录</span>');
						}
						cont.push('</tbody></table>');
					}
					else alert(JUtil.msg.ajaxErr);
					panel.empty().append(cont.join(''));
				}
			});
		}
};
$(function() {
	info.init();
});
</script>
</body>
</html>